home *** CD-ROM | disk | FTP | other *** search
- Path: news.telsib.ru!voyager
- From: a-kovalenko@star.nmb.ru (Alexey Kovalenko)
- Newsgroups: comp.lang.c++
- Subject: Re: C calling C++ function !!!
- Date: Wed, 21 Feb 96 12:24:45 GMT
- Organization: NMB
- Message-ID: <4gf2ud$oo0_001@news.telsib.ru>
- NNTP-Posting-Host: voyager.nmb.ru
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- Hello, all.
-
- Few days ago Norm Bryar <normanb@halcyon.com> in his answer has written:
-
- >Something tells me it's not that simple.
- >
- [Skipped]
- >I believe the accepted thing to do is define a set of 'C' wrapper APIs
- >that you can export to your 'C' modules. Internally, your wrappers do
- >class method calls.
-
- It's wrong. Function in C++, defined as "C", just uses predefined C calling
- convention instead compiler's preferred.
-
- Real solution here (don't say "It will not work" - I'm using this ):
-
- Situation : I'm working on project that contain both C and C++ sources and I
- don't want to make C sources C++. I'm needing to call function-classmember
- from C sources . Function must return char* by index(access to indexed strings
- array, fuction in C used instead operator[] in C++).
-
- header contains:
- typedef char * (*MsgFunc)(int iNo );
-
- C++ file contains:
-
- #include "header.h"
- #include "cassdef.hpp"
-
- static Message * _Msg = new Message("messages.msg");
- static Message & Msg1 = *_Msg;
- // Two variables to avoid compiler warning about
-
- char * Msg( int iNo )
- {
- return Msg1[iNo]; // operator []
- }
-
- MsgFunc Msg = Msg1;
-
- And C file contains:
-
- #include "header.h"
- extern MsgFun Msg;
- {
- printf( Msg(3) );
- }
-
- So, I'm calling C++ opertaor and class initialises before the "main" function.
-
- =============================================================
- Alexy Kovalenko
- Siberian State Academy of Telecommunications and Informatics
-
- Internet:
- a-kovalenko@star.nmb.ru
- a-kovalenko@voyager.nmb.ru
- koval@cad.nsk.su
- =============================================================
- // To love and to weep of love not for shame.
-